home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / datefilt.arc / DATEFILT.C next >
C/C++ Source or Header  |  1987-02-05  |  2KB  |  90 lines

  1. #define TRUE 1
  2. #define FALSE 0
  3. #include <stdio.h>
  4.  
  5. struct date { int day,month,year; };
  6.  
  7. main(argc,argv)
  8. int argc;
  9. char *argv[];
  10. {
  11.     char buffer[80],size[15],temp1[30],temp2[30],date[20];
  12.     char *bufptr, *gets();
  13.     int status,type,do_it;
  14.     char sign;
  15.     struct date temp;
  16.     struct date comp;
  17.     
  18.     if (argc != 3) { printf("Usage date1 op date\n   op -> 1 - < 2 - = 3 - >"); exit(1); }
  19.     type = atoi(argv[1]);
  20.     if (type == 1) sign = '<';
  21.     if (type == 2) sign = '=';
  22.     if (type == 3) sign = '>';
  23.     sscanf(argv[2],"%d/%d/%d",&comp.month,&comp.day,&comp.year);
  24.     fprintf(stderr,"Request: Files %c %s\n",sign,argv[2]);
  25.     bufptr = gets(buffer);
  26.     while (bufptr != NULL) {
  27.         if (strlen(bufptr) == 55) {
  28.             strncpy(temp1,buffer+2,12);
  29.             strncpy(date,buffer+46,9);
  30.             get_date(date,&temp);
  31.             do_it = FALSE;
  32.             switch (type) {
  33.             case 1 : if (datecmp(&comp,&temp) < NULL)
  34.                     do_it = TRUE;
  35.                     break;
  36.             case 2 : if (datecmp(&comp,&temp) == NULL)
  37.                     do_it = TRUE;
  38.                     break;
  39.             case 3 : if (datecmp(&comp,&temp) > NULL)
  40.                     do_it = TRUE;
  41.                     break;
  42.             }
  43.             if (do_it) printf("%s\n",buffer);
  44.         } else printf("%s\n",buffer);
  45.         bufptr = gets(buffer);
  46.     }
  47. }
  48.  
  49. int month_no(month)
  50. char month[];
  51. {
  52.     static char *chk_month[] = { "JAN","FEB","MAR","APR","MAY",
  53.                      "JUN","JUL","AUG","SEP","OCT",
  54.                      "NOV","DEC" };
  55.     int i;
  56.     
  57.     for (i=0;i<3;i++) month[i] = toupper(month[i]);
  58.     for (i=0;i<12;i++) 
  59.         if (strncmp(month,chk_month[i],3) == NULL)
  60.             return(i+1);
  61.     return(0);            
  62. }
  63.                
  64. int get_date(date,a)
  65. char date[];
  66. struct date *a;
  67. {
  68.     a->month = month_no(date);
  69.     sscanf(date+4,"%d %d",&(a->day),&(a->year));
  70. }
  71.                
  72.                
  73. int datecmp(a,b)
  74. struct date *a;
  75. struct date *b;
  76. {
  77.     if ((a->year == b->year) && (a->month == b->month) && (a->day == b->day))
  78.         return(0);
  79.     if ((a->year == b->year) && (a->month == b->month) && (a->day > b->day))
  80.         return(-1);
  81.     if ((a->year == b->year) && (a->month == b->month) && (a->day < b->day))
  82.         return(1);
  83.     if ((a->year == b->year) && (a->month > b->month))
  84.         return(-1);
  85.     if ((a->year == b->year) && (a->month < b->month))
  86.         return(1);
  87.     if (a->year < b->year) return(1);
  88.     if (a->year > b->year) return(-1);
  89. }
  90.